package org.noote.libs.virtualpad;

import java.util.ArrayList;

import android.view.MotionEvent;

public class VirtualPad_Input extends ArrayList<VirtualTouchPad> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1138702234248677448L;
	
	public void touch(MotionEvent event, boolean bMultiTouch)
	{
		for(VirtualTouchPad pad : this)
		{
			if(bMultiTouch)
			{
				for (int i = 0; i < event.getPointerCount(); i++) {
					if (event.getAction() == MotionEvent.ACTION_DOWN)
			        {   
						pad.setTouchEvent((int)event.getX(i), (int)event.getY(i), event.getPointerId(i), VirtualTouchPad.TOUCH_PRESSED);
			        }
					else if (event.getAction() == MotionEvent.ACTION_MOVE)
			        {   
						pad.setTouchEvent((int)event.getX(i), (int)event.getY(i), event.getPointerId(i), VirtualTouchPad.TOUCH_MOVED);
			        }
					else if (event.getAction() == MotionEvent.ACTION_UP)
			        {   
						pad.setTouchEvent((int)event.getX(i), (int)event.getY(i), event.getPointerId(i), VirtualTouchPad.TOUCH_RELEASED);
			        }
				}
			}
			else
			{
				if (event.getAction() == MotionEvent.ACTION_DOWN)
				{
						pad.setTouchEvent((int)event.getX(), (int)event.getY(), 0, VirtualTouchPad.TOUCH_PRESSED);
				}
				else if (event.getAction() == MotionEvent.ACTION_MOVE)
				{
						pad.setTouchEvent((int)event.getX(), (int)event.getY(), 0, VirtualTouchPad.TOUCH_MOVED);
				}
				else if (event.getAction() == MotionEvent.ACTION_UP)
				{
						pad.setTouchEvent((int)event.getX(), (int)event.getY(), 0, VirtualTouchPad.TOUCH_RELEASED);
				}
			}
		}
	}
}
